package com.meelive.ingkee.push.platform.oppo;

import android.content.Context;
import android.util.Log;

import com.heytap.msp.push.HeytapPushManager;
import com.heytap.msp.push.callback.ICallBackResultService;
import com.meelive.ingkee.push.InkePushConfig;
import com.meelive.ingkee.push.InkePushHelper;
import com.meelive.ingkee.push.model.Constance;
import com.meelive.ingkee.push.model.InkePushType;
import com.meelive.ingkee.push.common.PushUtils;
import com.meelive.ingkee.push.platform.IPush;

import static com.meelive.ingkee.push.model.Constance.TAG;

/**
 * Create by: fanfeiyue on: 2019-08-22 desc:
 */
public class InkeOppoPush extends IPush {

    @Override
    public InkePushType getPushType() {
        return InkePushType.OPPOPUSH;
    }

    @Override
    public void onRegister(Context context, InkePushConfig config) {
        if (PushUtils.DEBUG) {
            Log.d(TAG, "InkeOppoPush onRegister");
        }
        HeytapPushManager.init(context, PushUtils.DEBUG);
        boolean support = HeytapPushManager.isSupportPush(context);
        if (!support) {
            InkePushHelper.getInstance().onErrorResponse(InkePushType.OPPOPUSH, Constance.PUSH_NOT_SUPPORT, Constance.PUSH_NOT_SUPPORT_MSG);
            return;
        }

        HeytapPushManager.register(context, config.getOppoAppKey(), config.getOppoAppSecret(),
                new ICallBackResultService() {
                    @Override
                    public void onRegister(int responseCode, String registerID) {
                        if (responseCode == 0) {
                            InkePushHelper.getInstance().onReceiveToken(getPushType(), registerID);
                        } else {
                            InkePushHelper.getInstance().onErrorResponse(getPushType(), responseCode, "");
                        }
                    }

                    @Override
                    public void onUnRegister(int i) {

                    }

                    @Override
                    public void onSetPushTime(int i, String s) {

                    }

                    @Override
                    public void onGetPushStatus(int i, int i1) {

                    }

                    @Override
                    public void onGetNotificationStatus(int i, int i1) {

                    }

                    @Override
                    public void onError(int i, String s) {
                        InkePushHelper.getInstance().onErrorResponse(getPushType(), i, s);
                    }
                });
    }

    @Override
    public void onUnregister(Context context, InkePushConfig config) {
        HeytapPushManager.unRegister();
    }

}
